package com.koron.css2.serviceManage.impl;


import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserFieldBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.UserFieldConfigMapper;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 用户字段配置删除
 * 
 * @author 甄玉晴
 *
 */
public class UserFieldConfigDelete implements ServerInterface {

	private static Logger logger = LogManager.getLogger(UserFieldConfigDelete.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			UserFieldBean bean = JsonUtils.objectToPojo(req.getData(), UserFieldBean.class);
			if(bean == null ||StringUtils.isEmpty(bean.getId())) {
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "主键不能为空", void.class);
			}
			//校验字段
			UserFieldConfigMapper mapper = factory.getMapper(UserFieldConfigMapper.class);
			//删除
			mapper.deleteUserFieldConfig(bean.getId());
		} catch (Exception e) {
			logger.error("非法参数", e);
			return MessageBean.create(Constant.ILLEGAL_PARAMETER, "非法参数", void.class);
		}
		return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
	}
}
